package com.example.a514;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ThreadActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn_replace;
    private TextView tv_text;
    private View view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_thread);
        btn_replace = findViewById(R.id.btn_replace);
        tv_text = findViewById(R.id.tv_text);
        view = findViewById(R.id.view);

        btn_replace.setOnClickListener(this);
        Log.e("TAG", "onCreate: " + tv_text.getText().toString() );
    }



    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_replace) {
            new Thread(new Runnable() {
                @Override
                public void run() {

                    tv_text.setText("(Looper.getMainLooper().getThread() == Thread.currentThread())(Looper.getMainLooper().getThread() == Thread.currentThread())(Looper.getMainLooper().getThread() == Thread.currentThread())(Looper.getMainLooper().getThread() == Thread.currentThread())");
                    tv_text.invalidate();
//                    ViewGroup.LayoutParams layoutParams = tv_text.getLayoutParams();
//                    layoutParams.height = 100;

//                    tv_text.setLayoutParams(layoutParams);
                    view.setBackgroundColor(Color.BLACK);
                }
            }).start();
        }
    }
}